<?php
  //Buffer larger content areas like the main page content
  ob_start();
?><?php 
	include("config.php");

 require_once("auth.php"); ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<script type="text/javascript" src="js/validationsubcat.js"></script>
<script>
var count=0;

function load(thediv, thefile) /* 2 parameters passed into here: the id of the div container and the name of the page to go to */
{  
    if (window.XMLHttpRequest)
    {
        xmlhttp = new XMLHttpRequest();
    }
    else
    {
        xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');  
    }
    xmlhttp.addEventListener("error", transferFailed, false);  
    xmlhttp.onreadystatechange = function()
    {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
        {
            document.getElementById( thediv ).innerHTML = xmlhttp.responseText;
        }
    }  
 
   xmlhttp.open('GET', thefile, true);
    xmlhttp.send();
	    
}

function transferFailed(evt) {  
  alert("An error occurred while transferring the file.");  
}

</script>

</head>
<body>
<?php 
if(isset($_REQUEST['id']))
{

$id=$_REQUEST['id'];
$data=mysql_query("select * from subcategory where subcatid='$id'");
$no=mysql_num_rows($data);
if($no!=0)
{
	while($row=mysql_fetch_assoc($data))
	{
?>

<form action="updatesubcategorys.php" method="post"  enctype="multipart/form-data" id="frmCategory">
<fieldset >
<legend style="color:#FD0002">Update Categories </legend>
			<div id="status"></div>

<table width="50%"  align="center">
<tr><td width="99">Main Category</td><td width="247"><select name="ddlmcategory" id="ddlmcategory" onchange="funchange(this.value);">
						<?php
                        $data=mysql_query("select * from maincategories");
                        $no=mysql_num_rows($data);
                        if($no>0)
                        {
                            while($rec=mysql_fetch_assoc($data))
                            {
                        
                        ?><option <?php if($row['maincatname']==$rec['maincatname']) echo "selected='selected'"; ?>><?php echo $rec['maincatname']; ?> </option>
                        <?php
                            }
                        }
                        ?>

                    </select></td></tr>
<tr> 
				<td>Sub Category Name<span style="color:#FF0000">*</span></td>
				<td>
				<input type="hidden" name="id" value="<?php echo $id; ?>" />
				<input type="text" name="txtCategoryName" id="txtCategoryName" value="<?php echo $row['subcatname']; ?>">
				</td>
</tr>
<tr> 
				<td>Description</td><td><textarea id="textDescription" name="textDescription"><?php echo $row['desc']; ?></textarea></td></tr>
<tr><td colspan="2" align="right"><input type="button" name="btnUpdateCategory" id="btnUpdateCategory" value="Update Category"
 onclick="validateForm2('updatesubcategorys.php','frmCategory','thediv','<img src=\'pleasewait.gif\'>');" /></td></tr>
</table>
</fieldset>
  	</form>
	<?php
	}}
	}
	else
	{
	?>
<form action="addsubcategorys.php" method="post"  enctype="multipart/form-data" id="frmCategory">
<fieldset >
<legend style="color:#FD0002">Add Categories </legend>
			<div id="status"></div>

<table width="50%"  align="center">
<tr><td width="99">Main Category</td><td width="247"><select name="ddlmcategory" id="ddlmcategory" onchange="funchange(this.value);">
						<?php
                        $data=mysql_query("select * from maincategories");
                        $no=mysql_num_rows($data);
                        if($no>0)
                        {
                            while($rec=mysql_fetch_assoc($data))
                            {
                        
                        ?><option ><?php echo $rec['maincatname']; ?> </option>
                        <?php
                            }
                        }
                        ?>

                    </select></td></tr>

<tr> 
				<td>Category Name<span style="color:#FF0000">*</span></td>
				<td><input type="text" name="txtCategoryName" id="txtCategoryName">
				</td>
</tr>
<tr> 
				<td>Description</td><td><textarea id="textDescription" name="textDescription"></textarea></td></tr>
<tr><td colspan="2" align="right"><input type="button" name="btnCategory" id="btnCategory" value="Add Category" onclick="validateForm2('addsubcategorys.php','frmCategory','thediv','<img src=\'pleasewait.gif\'>');" /></td></tr>
</table>
</fieldset>
  	</form>
	
	
	<?php
	}
	?>
	
</body>
</html>
 <?php
  //Assign all Page Specific variables
  $pagemaincontent = ob_get_contents();
  ob_end_clean();
  $pagetitle = "Categories";
  //Apply the template
  include("master.php");
?>    